package com.dzf.controller;

import com.dzf.entity.*;
import com.dzf.service.HotService;
import com.dzf.service.LargeFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author DZF
 * 轮播图 公共模块
 */

@RestController
@RequestMapping("/api/public")
public class PublicController {

    @Autowired
    HotService hotService;
    @Autowired
    LargeFileService largeFileService;

    /**
     * 轮播图分页
     * @param num 每页数量
     * @param type  轮播图的类型
     * @return 查询结果
     */
    @RequestMapping("/findHot/{num}/{type}")
    public RespJson findHot(@PathVariable("num")int num,@PathVariable("type")int type){
        Map<String, Object> map = new HashMap<>();
        map.put("num",num);
        map.put("type",type);
        List<Hot> hots = hotService.findHot(map);
        return RespJson.pack(200,"ok",hots);
    }


    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }
}
